﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TImSdk
{
    public static class StringExtension
    {
        /// <summary>
        /// 获取UTF-8 字符
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetUTF8String(this string str)
        {
            byte[] bytes = Encoding.Default.GetBytes(str);
            var myString = Encoding.UTF8.GetString(bytes);
            return myString;
        }
        /// <summary>
        /// 转为UTF-8
        /// </summary>
        /// <param name="unicodeString"></param>
        /// <returns></returns>
        public static string ToUTF8String(this string unicodeString)
        {
            UTF8Encoding utf8 = new UTF8Encoding();
            byte[] encodedBytes = utf8.GetBytes(unicodeString);
            string decodedString = utf8.GetString(encodedBytes);
            return decodedString;
        }
        /// <summary>
        /// string转UTF byte[]
        /// </summary>
        /// <param name="unicodeString"></param>
        /// <returns></returns>
        public static byte[] ToUTF8Bytes(this string unicodeString)
        {
            UTF8Encoding utf8 = new UTF8Encoding();
            byte[] encodedBytes = utf8.GetBytes(unicodeString);
            return encodedBytes;
        }


    }
}
